//
//  ARMovieCell.m
//  AriseSamePro
//
//  Created by 包日守 on 15/11/2.
//  Copyright © 2015年 Arise. All rights reserved.
//

#import "ARMovieCell.h"


@interface ARMovieCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImageVeiw;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UIImageView *movieImageView;
@property (weak, nonatomic) IBOutlet UILabel *movieTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *directLabel;
@property (weak, nonatomic) IBOutlet UILabel *actorLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *likesLabel;
@property (weak, nonatomic) IBOutlet UILabel *viewsLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *hightConstraint;
@property (weak, nonatomic) IBOutlet UIButton *likeButton;
@property (weak, nonatomic) IBOutlet UIButton *playButton;


@end


@implementation ARMovieCell


- (IBAction)shareButtonClick:(id)sender {
    
    if (self.ShareBtnBlock) {
        self.ShareBtnBlock(self.cateModel,sender);
    }
}


- (void) setCateModel:(ARCate5Model *)cateModel
{
    _cateModel = cateModel;
    
    self.iconImageVeiw.layer.cornerRadius = 16;
    self.iconImageVeiw.clipsToBounds = YES;
    
    self.iconImageVeiw.image = nil;
    self.movieImageView.image = nil;
    
    [self.iconImageVeiw setImageWithURL:[NSURL URLWithString:cateModel.userModel.avatar]];
    [self.movieImageView setImageWithURL:[NSURL URLWithString:cateModel.mediaModel.movieModel.cover]];
    
    self.nameLabel.text = cateModel.userModel.username;
    self.movieTitleLabel.text = cateModel.mediaModel.movieModel.title;
    self.directLabel.text = cateModel.mediaModel.movieModel.director;
    self.actorLabel.text = cateModel.mediaModel.movieModel.actor;
    self.likesLabel.text = cateModel.likes.stringValue;
    self.viewsLabel.text = cateModel.views.stringValue;
    self.contentLabel.text = cateModel.txt;
    
    
    NSArray *arrayMP4 = [cateModel.mediaModel.movieModel.trailer componentsSeparatedByString:@"."];
    NSString *strMP4 = [arrayMP4 lastObject];
    
    if (![strMP4 isEqualToString:@"mp4"]) {
        self.playButton.hidden = YES;
    }
    else{
    
        self.playButton.hidden = NO;
    }
    
}


- (UIButton *) myLikeButton
{
    return self.likeButton;

}

- (IBAction)likeButtonClick:(id)sender {
    [self likeButtonAction];
    
}

- (IBAction)playButtonClick:(id)sender {
    
    if (self.delegate) {
        [self.delegate arMovieCell:self WithCate:self.cateModel];
    }
    
}


- (void)awakeFromNib {
    // Initialization code
    
    [self.playButton setImage:[UIImage imageNamed:@"pause@2x"] forState:UIControlStateSelected];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
